home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6595 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  46 lines

  1. Path: nntphub.cb.att.com!not-for-mail
  2. From: ka@socrates.hr.att.com (Kenneth Almquist)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c
  4. Subject: Re: C++ vs Ada for large project
  5. Date: 9 Feb 1996 23:57:49 GMT
  6. Organization: AT&T Bell Laboratories, Columbus, Ohio
  7. Message-ID: <4fgn1t$ku8@nntpa.cb.att.com>
  8. References: <w4wx5wc1a2.fsf@cln46ac> <4ffjrq$i8k@qualcomm.com>
  9. NNTP-Posting-Host: socrates.hr.att.com
  10.  
  11. Here is a real life story which illustrates why ".h" files are not
  12. a substitute for modules.  A few years ago I was using a C++ compiler
  13. which came with some libraries and header files.  Those of you
  14. familiar with UNIX know that UNIX provides a function which can be
  15. declared in C++ as
  16.  
  17.     extern "C" unsigned int alarm(unsigned int);
  18.  
  19. A couple of these header files provided with the compiler contained
  20. the definition:
  21.  
  22.     extern "C" unsigned int alarm(unsigned long);
  23.  
  24. This definition is incompatible with the definition of the UNIX alarm
  25. function, so if you included one of these header files in code which
  26. used the UNIX alarm function the compiler would reject it as an error.
  27.  
  28. No real problem, you say.  If you need to use the UNIX alarm function,
  29. just don't include the header files that misdefine it.
  30.  
  31. This would be simple if C++ header files acted like modules, but they
  32. don't.  Suppose you are writing two header files named a.h and b.h,
  33. and a.h needs to use a definition which appears in b.h.  The way you
  34. accomplish this in C++ is to have a.h include b.h.  The problem is
  35. that this has the effect of making a.h export all the names which are
  36. defined in b.h.  As a result, the set of definitions exported by a C++
  37. header file often include definitions which have little in common with
  38. each other.  And the misdefinitions of alarm (and several other UNIX
  39. system calls) were exported from some unpredicatable and suprising
  40. places.
  41.  
  42. I was able to work around the problem, but probably spent a week doing
  43. it, and this was on a relatively small program.  The larger the program,
  44. the harder header files are to manage.
  45.             Kenneth Almquist
  46.